﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using Toolkit;

namespace BusinessObjects {
  /// <summary>
  /// Child Diary
  /// </summary>
  public class ChildDiary : ObjectBase {

    private int id, childId;
    private string arrivalTime, departureTime, eatTime1, eatTime2, eatTime3, sleepTimeFrom, childRemarks;
    private string sleepTimeTo, eatComment, sleepComment, toiletComment, dayComment, noteComment;
    private DateTime day, arrivalDateTime, departureDateTime;
    private DateTime? childDateIn, childDateOut;
    private Image photo;
    private string firstName, name;

    #region - Properties -

    /// <summary>
    /// Gets or sets the id.
    /// </summary>
    /// <value>
    /// The id.
    /// </value>
    public int Id {
      get { return id; }
      set { id = value; }
    }

    /// <summary>
    /// Gets the state of the child.
    /// </summary>
    /// <value>
    /// The state of the child.
    /// </value>
    public BusinessObjects.Child.State ChildState {
      get {
        if ( ChildDateOut.HasValue ) {
          return BusinessObjects.Child.State.Inactive;
        } else {
          return BusinessObjects.Child.State.Active;
        }
      }
    }

    /// <summary>
    /// Gets the active state of the child .
    /// </summary>
    /// <value>
    /// The active state of the child .
    /// </value>
    public BusinessObjects.Child.ActiveState ChildActiveState {
      get {
        if ( ChildDateOut.HasValue ) {
          return BusinessObjects.Child.ActiveState.Gone;
        } else {
          if ( IsDepartureTimeEmpty( ) && !IsArrivalTimeEmpty( ) && ArrivalDateTime <= DateTime.Now ) {
            return BusinessObjects.Child.ActiveState.Present;
          } else if ( !IsDepartureTimeEmpty( ) && ArrivalDateTime <= DateTime.Now && DateTime.Now > DepartureDateTime ) {
            return BusinessObjects.Child.ActiveState.Present;
          } else {
            return Child.ActiveState.Absent;
          }
        }
      }
    }

    /// <summary>
    /// Gets or sets the day.
    /// </summary>
    /// <value>
    /// The day.
    /// </value>
    public DateTime Day {
      get { return day; }
      set { SetField( ref day, value, "Day" ); }
    }

    /// <summary>
    /// Gets or sets the arrival time.
    /// </summary>
    /// <value>
    /// The arrival time.
    /// </value>
    public string ArrivalTime {
      get { return arrivalTime; }
      set { SetField( ref arrivalTime, value, "ArrivalTime" ); }
    }

    /// <summary>
    /// Gets the arrival date time.
    /// </summary>
    public DateTime ArrivalDateTime {
      get {
        TimeSpan time = DateTimeTools.Convert.ToTimeSpan( arrivalTime );
        arrivalDateTime = day.Add( time );
        return arrivalDateTime;
      }
    }

    /// <summary>
    /// Gets or sets the departure time.
    /// </summary>
    /// <value>
    /// The departure time.
    /// </value>
    public string DepartureTime {
      get { return departureTime; }
      set { SetField( ref departureTime, value, "DepartureTime" ); }
    }

    /// <summary>
    /// Gets the departure date time.
    /// </summary>
    public DateTime DepartureDateTime {
      get {
        TimeSpan time = DateTimeTools.Convert.ToTimeSpan( departureTime );
        departureDateTime = day.Add( time );
        return departureDateTime;
      }
    }

    /// <summary>
    /// Gets or sets the child id.
    /// </summary>
    /// <value>
    /// The child id.
    /// </value>
    public int ChildId {
      get { return childId; }
      set { SetField( ref childId, value, "ChildId" ); }
    }

    /// <summary>
    /// Gets or sets the child remarks.
    /// </summary>
    /// <value>
    /// The child remarks.
    /// </value>
    public string ChildRemarks {
      get { return childRemarks; }
      set { childRemarks = value; }
    }

    /// <summary>
    /// Gets or sets the sleep time.
    /// </summary>
    /// <value>
    /// The sleep time.
    /// </value>
    public string SleepTimeFrom {
      get { return sleepTimeFrom; }
      set { SetField( ref sleepTimeFrom, value, "SleepTime" ); }
    }

    /// <summary>
    /// Gets or sets the sleep time to.
    /// </summary>
    /// <value>
    /// The sleep time to.
    /// </value>
    public string SleepTimeTo {
      get { return sleepTimeTo; }
      set { SetField( ref sleepTimeTo, value, "SleepTime" ); }
    }

    /// <summary>
    /// Gets or sets the eat time.
    /// </summary>
    /// <value>
    /// The eat time.
    /// </value>
    public string EatTime1 {
      get { return eatTime1; }
      set { SetField( ref eatTime1, value, "EatTime" ); }
    }

    /// <summary>
    /// Gets or sets the eat time2.
    /// </summary>
    /// <value>
    /// The eat time2.
    /// </value>
    public string EatTime2 {
      get { return eatTime2; }
      set { SetField( ref eatTime2, value, "EatTime" ); }
    }

    /// <summary>
    /// Gets or sets the eat time3.
    /// </summary>
    /// <value>
    /// The eat time3.
    /// </value>
    public string EatTime3 {
      get { return eatTime3; }
      set { SetField( ref eatTime3, value, "EatTime" ); }
    }

    /// <summary>
    /// Gets or sets the note comment.
    /// </summary>
    /// <value>
    /// The note comment.
    /// </value>
    public string NoteComment {
      get { return noteComment; }
      set { SetField( ref noteComment, value, "NoteComment" ); }
    }

    /// <summary>
    /// Gets or sets the day comment.
    /// </summary>
    /// <value>
    /// The day comment.
    /// </value>
    public string DayComment {
      get { return dayComment; }
      set { SetField( ref dayComment, value, "DayComment" ); }
    }

    /// <summary>
    /// Gets or sets the toilet comment.
    /// </summary>
    /// <value>
    /// The toilet comment.
    /// </value>
    public string ToiletComment {
      get { return toiletComment; }
      set { SetField( ref toiletComment, value, "ToiletComment" ); }
    }

    /// <summary>
    /// Gets or sets the sleep comment.
    /// </summary>
    /// <value>
    /// The sleep comment.
    /// </value>
    public string SleepComment {
      get { return sleepComment; }
      set { SetField( ref sleepComment, value, "SleepComment" ); }
    }

    /// <summary>
    /// Gets or sets the eat comment.
    /// </summary>
    /// <value>
    /// The eat comment.
    /// </value>
    public string EatComment {
      get { return eatComment; }
      set { SetField( ref eatComment, value, "EatComment" ); }
    }

    /// <summary>
    /// Gets or sets the photo.
    /// </summary>
    /// <value>
    /// The photo.
    /// </value>
    public Image Photo {
      get { return photo; }
      set { photo = value; }
    }

    /// <summary>
    /// Gets or sets the first name.
    /// </summary>
    /// <value>
    /// The first name.
    /// </value>
    public string FirstName {
      get { return firstName; }
      set { firstName = value; }
    }

    /// <summary>
    /// Gets or sets the name.
    /// </summary>
    /// <value>
    /// The name.
    /// </value>
    public string Name {
      get { return name; }
      set { name = value; }
    }

    /// <summary>
    /// Gets the full name.
    /// </summary>
    public string FullName {
      get { return firstName + " " + name; }
    }

    /// <summary>
    /// Gets or sets the child date out.
    /// </summary>
    /// <value>
    /// The child date out.
    /// </value>
    public DateTime? ChildDateOut {
      get { return childDateOut; }
      set { childDateOut = value; }
    }

    /// <summary>
    /// Gets or sets the child date in.
    /// </summary>
    /// <value>
    /// The child date in.
    /// </value>
    public DateTime? ChildDateIn {
      get { return childDateIn; }
      set { childDateIn = value; }
    }

    #endregion

    #region - Public methods -

    /// <summary>
    /// Copies this instance.
    /// </summary>
    /// <returns></returns>
    public ChildDiary Copy( ) {
      ChildDiary copy = new ChildDiary( );
      copy.Id = this.Id;
      copy.ChildId = this.ChildId;
      copy.ArrivalTime = this.ArrivalTime;
      copy.DepartureTime = this.DepartureTime;
      copy.Day = this.Day;
      copy.DayComment = this.DayComment;
      copy.EatTime1 = this.EatTime1;
      copy.EatTime2 = this.EatTime2;
      copy.EatTime3 = this.EatTime3;
      copy.EatComment = this.EatComment;
      copy.SleepTimeFrom = this.SleepTimeFrom;
      copy.SleepTimeTo = this.SleepTimeTo;
      copy.SleepComment = this.SleepComment;
      copy.ToiletComment = this.ToiletComment;
      copy.NoteComment = this.NoteComment;
      copy.Name = this.Name;
      copy.FirstName = this.FirstName;
      copy.Photo = this.Photo;
      copy.ChildRemarks = this.ChildRemarks;
      copy.MarkClean( );

      return copy;
    }

    /// <summary>
    /// Determines whether [is arrival time empty].
    /// </summary>
    /// <returns>
    ///   <c>true</c> if [is arrival time empty]; otherwise, <c>false</c>.
    /// </returns>
    public bool IsArrivalTimeEmpty( ) {
      return ( string.IsNullOrEmpty( ArrivalTime ) || string.IsNullOrEmpty( ArrivalTime.Trim( ) ) || ArrivalTime.Trim( ) == ":" || ArrivalTime == "00:00" );
    }

    /// <summary>
    /// Determines whether [is departure time empty].
    /// </summary>
    /// <returns>
    ///   <c>true</c> if [is departure time empty]; otherwise, <c>false</c>.
    /// </returns>
    public bool IsDepartureTimeEmpty( ) {
      return ( string.IsNullOrEmpty( DepartureTime ) || string.IsNullOrEmpty( DepartureTime.Trim( ) ) || DepartureTime.Trim( ) == ":" || DepartureTime == "00:00" );
    }

    #endregion


  }
}
